﻿using System;
using System.Configuration;
using Common.Logging;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration;

namespace Mayfair.Core.Common.DI
{
    public class Unity : AbstractDIContainer
    {
        private static ILog log = LogManager.GetLogger(typeof(Unity));
        private IUnityContainer container;

        public Unity()
        {
            container = new UnityContainer();
            UnityConfigurationSection section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
            section.Containers.Default.Configure(container);
        }

        public override T GetObject<T>(Object key)
        {
            log.Debug("オブジェクト取得要求です: " + (string)key);
            return container.Resolve<T>((string)key);
        }
    }
}
